package leetcode_top;
import org.junit.*;


public class Ex125 {
    class Solution {
        public boolean isPalindrome(String s) {
            int len;
            if (s == null || (len = s.length()) == 0) return true;
            int lo = 0, hi = len - 1;
            int a = 0, b = 0;
            char[] cs = s.toCharArray();
            while (lo < hi) {
                while (lo < hi && (a = test(cs[lo])) == 0) lo++;
                while (lo < hi && (b = test(cs[hi])) == 0) hi--;
                if (lo == hi) return true;
                if (a == b) {
                    if (cs[lo] != cs[hi]) return false;
                } else {
                    if (a == 1) {
                        if (cs[lo] != cs[hi] + 32) return false;
                    } else {
                        if (cs[lo] != cs[hi] - 32) return false;
                    }
                }
                lo++;
                hi--;
            }
            return true;
        }

        public int test(char c) {
            if (c >= 'a' && c <= 'z') return 1;
            else if (c >= 'A' && c <= 'Z')  return 2;
            else return 0;
        }
    }


    @Test
    public void test() {
        Solution s = new Solution();
        System.out.println('a' - 'A');
        System.out.println(s.isPalindrome("0P"));
    }
}
